package com.mrx.example.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mrx.example.dao.EmpDao;
import com.mrx.example.model.Result;
import com.mrx.example.servlet.BaseServlet;

@WebServlet(name = "删除员工 API", value = "/del")
public class DelController extends BaseServlet {

    private final EmpDao empDao = new EmpDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        // TODO: 根据 type 选择删除员工还是删除部门
        String type = req.getParameter("type");
        if (hasBlankOrNull(id, type)) {
            send404ModelResponse(resp, Result.E404);
        } else {
            sendModelResponse(resp, empDao.delEmp(id));
        }
    }

}
